package com.wangyadong.hobby.concurrent;

import java.util.concurrent.atomic.AtomicLong;

public class AtomicLongTest {
    public static void main(String[] args) {

        AtomicLong atomicLong = new AtomicLong(10);
        boolean compareAndSet = atomicLong.compareAndSet(0, 1);
        if (compareAndSet) {
            long number = atomicLong.get();
            assert number == 1L;
        }
        atomicLong.accumulateAndGet(5L, (x, y) -> {
            System.out.println("x=" + x + " y=" + y);
            return x + y;
        });
        System.out.println(atomicLong.get());
        System.out.println("=======================================");

        long andAdd = atomicLong.addAndGet(20);
        assert andAdd == 35L;

    }
}
